﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DataModel;
using P_PersonalDetails.Service.SlalomRanking;
namespace P_PersonalDetails
{
    public partial class SlalomRanking : UserControl
    {
        public SlalomRanking()
        {
            InitializeComponent();
            try
            {
                SRS.LoadRankingsCompleted += new EventHandler<LoadRankingsCompletedEventArgs>(SRS_LoadRankingsCompleted);
            }
            catch (Exception)
            {
            }
        }
        public static SlalomRankingsData SlalomRankingsDataContext { get; set; }

        void SRS_LoadRankingsCompleted(object sender, LoadRankingsCompletedEventArgs e)
        {
            this.DataContext = e.Result;
            SlalomRankingsDataContext = e.Result;
        }

        public int? MemberID
        {
            get { return (int?)GetValue(MemberIDProperty); }
            set { SetValue(MemberIDProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MemberID.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MemberIDProperty =
            DependencyProperty.Register("MemberID", typeof(int?), typeof(SlalomRanking), new PropertyMetadata(null, (DO, DE) =>
            {
                if (DE.NewValue != null)
                {
                    ((SlalomRanking)DO).MemberIDChanged();
                }
            }));

        void MemberIDChanged()
        {
            //MDS.GetMembershipDetailsAsync(MemberID.Value);
            SRS.LoadRankingsAsync(MemberID.Value);
        }



        SlalomRankingServiceClient SRS = ServiceConfig.NewSlalomRankingClient();

        private void AddDoubleDivision(object sender, RoutedEventArgs e)
        {
            SlalomRankingsDataContext.AddDoubleDivision();
        }
    }

    public class DeleteSRCommand:ICommand
    {

        #region ICommand Members

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged { add { } remove { } }

        public void Execute(object parameter)
        {
            SlalomRanking.SlalomRankingsDataContext.DeleteDoubleDivision((int)parameter);
            //SRV.DeleteSlalomRankingDataAsync((int)parameter);
        }

        #endregion

    }
}
